package com.google.code.netbuilder.logging;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

/**
 *
 * @author VIME0812
 */
public class StringCreator {

    public static String toString(Object obj) {
        if (obj == null) {
            return "null";
        }
        return obj.toString();
    }

    public static String toString(Collection collection) {
        if (collection == null) {
            return "null";
        }
        StringBuilder sb = new StringBuilder(collection.getClass().getSimpleName() + " of {");
        for (Object object : collection) {
            sb.append(toString(object));
            sb.append("\n");
        }
        sb.append("}");
        return sb.toString();
    }

    public static String toString(Object[] arr) {
        return toString(Arrays.asList(arr));
    }

    public static String toString(Map map) {
        if (map == null) {
            return "null";
        }
        StringBuilder sb = new StringBuilder(map.getClass().getSimpleName() + " of {");
        for (Object key : map.keySet()) {
            sb.append(toString(key));
            sb.append(": ");
            sb.append(toString(map.get(key)));
            sb.append("\n");
        }
        sb.append("}");
        return sb.toString();
    }
}
